<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.sql.*" import="Connect.*"%>
<%
	boolean has_auctions = false;
	java.sql.Connection conn = null;
	try {
		// Connect to the database.
		Class.forName(ConnectionInfo.myJDBCDriver()).newInstance();
		java.util.Properties sysprops = System.getProperties();
		sysprops.put("user", ConnectionInfo.myUserID());
		sysprops.put("password", ConnectionInfo.myPassword());
		conn = java.sql.DriverManager.getConnection(ConnectionInfo.myURL(), sysprops);
		String auction_owner = request.getParameter("auc");

		// Display a table of Auction information.
		java.sql.Statement statement = conn.createStatement();
		java.sql.ResultSet rs = statement.executeQuery("SELECT items.name, auctions.minimum_bid, auctions.bid_increment, auctions.open_date, auctions.end_date, auctions.monitor, auctions.owner"
						+ " FROM items RIGHT JOIN auctions ON items.id=auctions.item WHERE auctions.owner='" + auction_owner + "' AND end_date > NOW()");
		java.sql.ResultSetMetaData columns = rs.getMetaData();
		
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>
</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1><%=auction_owner%>'s Auctions
		</h1>
		<hr></hr>
	
		<table class="center data-table">
			<%
			out.println("<h2>Current Auctions</h2>");
				// Getting Auction information
					out.println("<tr>");
					for (int i = 1; i <= columns.getColumnCount(); i++) {
						out.println("<th>" + columns.getColumnName(i) + "</th>");
					}
					out.println("<th></th>");
					out.println("</tr>");
					while (rs.next()) {
						has_auctions = true;
						out.println("<tr>");
						for (int i = 1; i <= columns.getColumnCount(); i++) {
							out.println("<td align=center>" + rs.getString(columns.getColumnName(i)) + "</td>");
						}
					}
					out.println("</tr>");
					rs = statement.executeQuery("SELECT items.name, auctions.minimum_bid, auctions.bid_increment, auctions.open_date, auctions.end_date, auctions.monitor, auctions.owner"
							+ " FROM items RIGHT JOIN auctions ON items.id=auctions.item WHERE auctions.owner='" + auction_owner + "' AND end_date < NOW()");
					columns = rs.getMetaData();
					// Getting Auction information
						out.println("</table>");
					
					
					
					out.println("<h2>Expired Auctions</h2>");
					%>
					<table class="center data-table">
					<%
					out.println("<tr>");
					for (int i = 1; i <= columns.getColumnCount(); i++) {
						out.println("<th>" + columns.getColumnName(i) + "</th>");
					}
					out.println("<th></th>");
					out.println("</tr>");
					while (rs.next()) {
						has_auctions = true;
						out.println("<tr>");
						for (int i = 1; i <= columns.getColumnCount(); i++) {
							out.println("<td align=center>" + rs.getString(columns.getColumnName(i)) + "</td>");
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					try {
						conn.close();
					} catch (Exception ee) {
					}
				}
			%>
		</table>
		<table class="center">
			<tr>
				<td>
					<%
						if (!has_auctions) {
							out.println("<b>There were no auctions found that belong to this user.</b>");
						}
					%>
				</td>
			</tr>
		</table>
	</div>
	<hr></hr>
	<%@include file="footer.jsp"%>
</body>
</html>
